﻿using System;
using System.ComponentModel;

namespace Chapter11.Queries
{
    static class Extensions
    {
        //声明Where扩展方法
        public static Dummy<T> Where<T>(this Dummy<T> dummy,
                                        Func<T,bool> predicate)
        {
            Console.WriteLine("Where called");
            return dummy;
        }
    }

    class Dummy<T>
    {
        //声明Select实例方法
        public Dummy<U> Select<U>(Func<T,U> selector)
        {
            Console.WriteLine("Select called");
            return new Dummy<U>();
        }
    }
    //展示编译器转义调用伪LINQ实现中的方法
    [Description("Listing 11.03")]
    class TranslationExample
    {
        static void Main()
        {
            //创建查询数据源
            var source = new Dummy<string>();
            //通过查询表达式来调用方法
            var query = from dummy in source 
                        where dummy.ToString()=="Ignored"
                        select "Anything";
        }
    }
}

